#include <bits/stdc++.h>
// 2025/04/01
// tag:
// Author: Zhang Muen
using namespace std;
class State {
public:
    int64_t id, weight;
    State(int64_t i, int64_t w)
    {
        id = i;
        weight = w;
    }
};

struct cmp {
    bool operator()(State& a, State& b)
    {
        return a.weight > b.weight;
    }
};

int64_t n, m, s, x1, Y1, x2, y2, d1[1501], d2[1501], d3[1501], d4[1501], dp[1501];
bool vis[1501];
vector<State> graph[1501], graph2[1501];

int64_t dfs(int64_t u)
{
    if (dp[u])
        return dp[u];
    for (auto e : graph2[u])
        dp[u] = max(dp[u], dfs(e.id) + e.weight);
    return dp[u];
}

void Dijkstra(int64_t start, int64_t* dist)
{
    for (int i = 1; i <= n; i++)
        dist[i] = INT64_MAX;
    priority_queue<State, vector<State>, cmp> pq;
    dist[start] = 0;
    pq.push(State(start, 0));
    while (!pq.empty()) {
        State state = pq.top();
        pq.pop();
        int64_t Dist = state.weight;
        if (Dist > dist[state.id])
            continue;
        for (auto neighbor : graph[state.id]) {
            int64_t Dist2 = Dist + neighbor.weight;
            if (dist[neighbor.id] > Dist2) {
                dist[neighbor.id] = Dist2;
                pq.push(State(neighbor.id, Dist2));
            }
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> m;
    cin >> x1 >> Y1 >> x2 >> y2;
    int64_t u, v, w;
    for (int i = 0; i < m; i++) {
        cin >> u >> v >> w;
        graph[u].push_back(State(v, w));
        graph[v].push_back(State(u, w));
    }
    Dijkstra(x1, d1), Dijkstra(x2, d2), Dijkstra(Y1, d3), Dijkstra(y2, d4);
    for (int i = 1; i <= n; i++)
        for (auto e : graph[i])
            if (d1[i] + e.weight + d3[e.id] == d1[Y1]) {
                if (d2[i] + e.weight + d4[e.id] == d2[y2])
                    graph2[i].push_back(State(e.id, e.weight)), vis[i] = vis[e.id] = true;
                if (d2[e.id] + e.weight + d4[i] == d2[y2])
                    graph2[e.id].push_back(State(i, e.weight)), vis[i] = vis[e.id] = true;
            }
    for (int i = 1; i <= n; i++)
        if (vis[i])
            dfs(i);
    int64_t ans = 0;
    for (int i = 1; i <= n; i++)
        ans = max(ans, dp[i]);
    cout << ans << endl;
    return 0;
}